
package br.com.moxirpt.controller.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import br.com.crfutil.component.date.IntegerDate;
import br.com.moxirpt.controller.util.FacesUtil;

/**
 * 
 *
 */
public class IntegerDateConverter implements Converter {
	
	public Object getAsObject(FacesContext context, UIComponent component, String value) {
		
		IntegerDate iDate = new IntegerDate();
		
		if (value.isEmpty()){
			return iDate;
		}
				
		try{
			iDate.setStrDate(value);
		}catch (Exception e) {
			FacesUtil.addMensagemErro(e.getMessage());
			//return "";
			//return iDate;
		}

		return iDate;
		
	}
	
	public String getAsString(FacesContext context, UIComponent component, Object value) {
		return value.toString();
	}
}
